package com.surenpi.jenkins.client.computer;

import com.google.common.base.Function;
import com.google.common.net.UrlEscapers;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ComputerWithDetails extends Computer {
   private String displayName;
   private Boolean idle;
   private Boolean jnlp;
   private Boolean launchSupported;
   private Boolean manualLaunchAllowed;
   private Map monitorData;
   private Integer numExecutors;
   private Boolean offline;
   private OfflineCause offlineCause;
   private String offlineCauseReason;
   private List oneOffExecutors;
   private Boolean temporarilyOffline;
   private List<Label> assignedLabels;
   private String absoluteRemotePath;

   public String getDisplayName() {
      return this.displayName;
   }

   public Boolean getIdle() {
      return this.idle;
   }

   public Boolean getJnlp() {
      return this.jnlp;
   }

   public Boolean getLaunchSupported() {
      return this.launchSupported;
   }

   public LoadStatistics getLoadStatistics() throws IOException {
      String name;
      if ("master".equals(this.displayName)) {
         name = "(master)";
      } else {
         name = UrlEscapers.urlPathSegmentEscaper().escape(this.displayName);
      }

      return (LoadStatistics)this.getClient().get("/computer/" + name + "/loadStatistics/?depth=2", LoadStatistics.class);
   }

   public void toggleOffline(boolean crumbFlag) throws IOException {
      String name;
      if ("master".equals(this.displayName)) {
         name = "(master)";
      } else {
         name = UrlEscapers.urlPathSegmentEscaper().escape(this.displayName);
      }

      Map<String, String> data = new HashMap();
      data.put("json", "init");
      this.getClient().post("/computer/" + name + "/toggleOffline", crumbFlag);
   }

   public void toggleOffline() throws IOException {
      this.toggleOffline(false);
   }

   public void changeOfflineCause(String cause, boolean crumbFlag) throws IOException {
      String name;
      if ("master".equals(this.displayName)) {
         name = "(master)";
      } else {
         name = UrlEscapers.urlPathSegmentEscaper().escape(this.displayName);
      }

      Map<String, String> data = new HashMap();
      data.put("offlineMessage", cause);
      this.getClient().postForm("/computer/" + name + "/changeOfflineCause?", data, crumbFlag);
   }

   public void changeOfflineCause(String cause) throws IOException {
      this.changeOfflineCause(cause, false);
   }

   public Boolean getManualLaunchAllowed() {
      return this.manualLaunchAllowed;
   }

   public Map<String, Map> getMonitorData() {
      return this.monitorData;
   }

   public Integer getNumExecutors() {
      return this.numExecutors;
   }

   public Boolean getOffline() {
      return this.offline;
   }

   public OfflineCause getOfflineCause() throws IOException {
      return this.offlineCause;
   }

   public String getOfflineCauseReason() {
      return this.offlineCauseReason;
   }

   public List<Map> getOneOffExecutors() {
      return this.oneOffExecutors;
   }

   public Boolean getTemporarilyOffline() {
      return this.temporarilyOffline;
   }

   public List<Label> getAssignedLabels() {
      return this.assignedLabels;
   }

   public void setAssignedLabels(List<Label> assignedLabels) {
      this.assignedLabels = assignedLabels;
   }

   public String getAbsoluteRemotePath() {
      return this.absoluteRemotePath;
   }

   public void setAbsoluteRemotePath(String absoluteRemotePath) {
      this.absoluteRemotePath = absoluteRemotePath;
   }

   public boolean equals(Object obj) {
      if (this == obj) {
         return true;
      } else if (!super.equals(obj)) {
         return false;
      } else if (this.getClass() != obj.getClass()) {
         return false;
      } else {
         ComputerWithDetails other = (ComputerWithDetails)obj;
         if (this.displayName == null) {
            if (other.displayName != null) {
               return false;
            }
         } else if (!this.displayName.equals(other.displayName)) {
            return false;
         }

         if (this.idle == null) {
            if (other.idle != null) {
               return false;
            }
         } else if (!this.idle.equals(other.idle)) {
            return false;
         }

         if (this.jnlp == null) {
            if (other.jnlp != null) {
               return false;
            }
         } else if (!this.jnlp.equals(other.jnlp)) {
            return false;
         }

         if (this.launchSupported == null) {
            if (other.launchSupported != null) {
               return false;
            }
         } else if (!this.launchSupported.equals(other.launchSupported)) {
            return false;
         }

         if (this.manualLaunchAllowed == null) {
            if (other.manualLaunchAllowed != null) {
               return false;
            }
         } else if (!this.manualLaunchAllowed.equals(other.manualLaunchAllowed)) {
            return false;
         }

         if (this.monitorData == null) {
            if (other.monitorData != null) {
               return false;
            }
         } else if (!this.monitorData.equals(other.monitorData)) {
            return false;
         }

         if (this.numExecutors == null) {
            if (other.numExecutors != null) {
               return false;
            }
         } else if (!this.numExecutors.equals(other.numExecutors)) {
            return false;
         }

         if (this.offline == null) {
            if (other.offline != null) {
               return false;
            }
         } else if (!this.offline.equals(other.offline)) {
            return false;
         }

         if (this.offlineCause == null) {
            if (other.offlineCause != null) {
               return false;
            }
         } else if (!this.offlineCause.equals(other.offlineCause)) {
            return false;
         }

         if (this.offlineCauseReason == null) {
            if (other.offlineCauseReason != null) {
               return false;
            }
         } else if (!this.offlineCauseReason.equals(other.offlineCauseReason)) {
            return false;
         }

         if (this.oneOffExecutors == null) {
            if (other.oneOffExecutors != null) {
               return false;
            }
         } else if (!this.oneOffExecutors.equals(other.oneOffExecutors)) {
            return false;
         }

         if (this.temporarilyOffline == null) {
            if (other.temporarilyOffline != null) {
               return false;
            }
         } else if (!this.temporarilyOffline.equals(other.temporarilyOffline)) {
            return false;
         }

         return true;
      }
   }

   public int hashCode() {
      int prime = 31;
      int result = super.hashCode();
      result = 31 * result + (this.displayName == null ? 0 : this.displayName.hashCode());
      result = 31 * result + (this.idle == null ? 0 : this.idle.hashCode());
      result = 31 * result + (this.jnlp == null ? 0 : this.jnlp.hashCode());
      result = 31 * result + (this.launchSupported == null ? 0 : this.launchSupported.hashCode());
      result = 31 * result + (this.manualLaunchAllowed == null ? 0 : this.manualLaunchAllowed.hashCode());
      result = 31 * result + (this.monitorData == null ? 0 : this.monitorData.hashCode());
      result = 31 * result + (this.numExecutors == null ? 0 : this.numExecutors.hashCode());
      result = 31 * result + (this.offline == null ? 0 : this.offline.hashCode());
      result = 31 * result + (this.offlineCause == null ? 0 : this.offlineCause.hashCode());
      result = 31 * result + (this.offlineCauseReason == null ? 0 : this.offlineCauseReason.hashCode());
      result = 31 * result + (this.oneOffExecutors == null ? 0 : this.oneOffExecutors.hashCode());
      result = 31 * result + (this.temporarilyOffline == null ? 0 : this.temporarilyOffline.hashCode());
      return result;
   }

   private class ComputerWithClient implements Function<Computer, Computer> {
      public Computer apply(Computer computer) {
         computer.setClient(ComputerWithDetails.this.getClient());
         return computer;
      }
   }
}
